package io.github.maojian.bianrysearch;

import org.junit.Test;

/**
 * @Auther: jian.mao
 * @Date: 2022-06-22 11:25
 * @Description: https://leetcode.cn/problems/peak-index-in-a-mountain-array/
 */
public class Q852 {
    public int peakIndexInMountainArray(int[] arr) {
        int length = arr.length;
        int left = 0, right = length - 1;
        while (left <= right) {
            int mid = (right - left) / 2 + left;
            if (arr[mid] > arr[mid + 1] && arr[mid] > arr[mid - 1]) {
                return mid;
            }
            if (arr[mid] < arr[mid + 1]) {
                left = mid + 1;
            } else {
                right = mid - 1;
            }

        }
        return 0;
    }

    @Test
    public void test() {
        int[] arr = new int[]{24,69,100,99,79,78,67,36,26,19};
        System.out.println(peakIndexInMountainArray(arr));
    }
}
